﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>友情链接 </title>
    <link href="../static/css/admin.css?v=6" rel="stylesheet" />
    <script src="../static/js/boot.js?v=2"></script>
    <script src="../static/js/admin.js?v=2"></script>

</head>
<body style="margin:0px;padding:0px;overflow:hidden;">
    <script type="text/javascript">
        var apiUrl = "/api/Friendlink/";
        $(function () {
            //数据表格
            var $gridList = $("#gridList");
            $gridList.dataGrid({
                url: apiUrl + "GetGridJson",
                postData: search_param(),
                datatype: "json",
                contentType: 'application/json',
                loadBeforeSend: function (jqXHR) {
                    jqXHR.setRequestHeader("Authorization", 'Bearer ' + window.LS.get("hdjtoken"));
                },
                height: $(window).height() - 148,
                autowidth: true,
                colModel: [
                    { label: "主键", name: "ID", hidden: true, key: true, frozen: true },
                    { label: '名称', name: 'Name', align: 'center' },
                    { label: 'Url', name: 'Url', align: 'center' },
                    { label: '描述', name: 'Description', align: 'center' },
                    {
                        label: "图标", name: "Icon", align: "center", width: 80,
                        formatter: function (cellvalue, options, rowObject) {
                            var keyId = rowObject.ID;
                            return ' <img id="headPic" src="/upfile/' + rowObject.Icon +'" style="width:64px;height:64px;" onerror="this.src=\'../static/img/jiahao.png\'" />';
                        }
                    },
                    {
                        label: "有效", name: "Status", align: "center", width: 80,
                        formatter: function (cellvalue, options, rowObject) {
                            var keyId = rowObject.ID;
                            return String(cellvalue).trim() == "1" ? "<i onclick='Switch(\"" + keyId + "\")' class=\"fa fa-toggle-on\"></i>" : "<i onclick='Switch(\"" + keyId + "\")' class=\"fa fa-toggle-off\"></i>";
                        }
                    },
                    { label: '排序', name: 'OrderBy', align: 'center' },
                    { label: '添加时间', name: 'AddTime', align: 'center' },
                ],
                rowNum: 20,
                rowList: [20, 50, 100],
                pager: '#gridPager',
                sortname: 'ID',
                viewrecords: true,
                sortorder: "asc",
                multiselect: true,
                ondblClickRow: function (rowID) {
                    var ret = jQuery("#gridList").jqGrid('getRowData', rowID);
                    var keyValue = ret.ID;
                    btn_edit(keyValue);
                }
            });
            //搜索事件
            $("#btn_search").click(function () {
                keyword = $("#txt_keyword").val();//搜索框变量
                $gridList.jqGrid('setGridParam', {
                    url: apiUrl + "GetGridJson",
                    postData: search_param(),
                }).trigger('reloadGrid');
            });
        });
        //新增
        function btn_add() {
            $.modalOpen({
                id: "Form",
                title: "新增",
                url: "friendlink/form.html",
                width: "800px",
                height: "600px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
        //编辑
        function btn_edit(id) {
            if (id == "" || id == undefined) {
                var ids = gridselId();
                if (ids == "" || ids == undefined) {
                    $.modalAlert("请选择一条数据", "warning");
                    return;
                }
                id = ids[0];
            }
            $.modalOpen({
                id: "Form",
                title: "修改",
                url: "friendlink/form.html?keyValue=" + id,
                width: "800px",
                height: "600px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
        //删除
        function btn_delete(id) {
            if (id == "" || id == undefined) {
                var ids = gridselId();
                if (ids == "" || ids == undefined) {
                    $.modalAlert("请选择数据", "warning");
                    return;
                }
                id = ids.join(",");
            }
            $.deleteForm({
                url: apiUrl + "DeleteForm?keyId=" + id,
                success: function () {
                    $("#gridList").trigger("reloadGrid");
                }
            });
        }
        // 1,2,3,4
        function gridselId() {
            var myArray = new Array()
            var s = $("#gridList").jqGrid('getGridParam', 'selarrrow');
            if (s.length > 0) {
                for (var i = 0; i < s.length; i++) {
                    if (s[i]) {
                        var ret = $("#gridList").jqGrid('getRowData', s[i]);
                        myArray.push(ret.ID);
                    }
                }
            } else {
                myArray.push($("#gridList").jqGridRowValue().ID);
            }
            return myArray;
        }
        function search_param() {
            var postData = {
                keyword: $("#txt_keyword").val()
            };
            return postData;
        }
        //关闭有效触发
        function Switch(keyId) {
            $.ajax({
                url: apiUrl + "Switch?keyId=" + keyId,
                data: {},
                type: "POST",
                dataType: "json",
                async: false,
                success: function () {
                    $.currentWindow().$("#gridList").resetSelection();
                    $.currentWindow().$("#gridList").trigger("reloadGrid");
                }
            });
        }
    </script>

    <div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
        <div class="ui-layout-west">
            <div id="itemTree"></div>
        </div>
        <div class="ui-layout-center">
            <div class="topPanel">
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="NF-add" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_add()"><i class="fa fa-plus"></i>新增</a>
                    </div>
                    <div class="btn-group">
                        <a id="NF-edit" authorize="yes" class="btn btn-warning dropdown-text" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改</a>
                    </div>
                    <div class="btn-group">
                        <a id="NF-delete" authorize="yes" class="btn btn-danger dropdown-text" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除</a>
                    </div>
                    <div class="btn-group">
                        <a id="NF-export" authorize="yes" class="btn btn-info dropdown-toggle" data-toggle="dropdown"><i class="fa fa-file-excel-o"></i>导出<span class="caret"></span></a>
                        <ul class="dropdown-menu" role="menu">
                            <li><a onclick="btn_export('JSON')">JSON</a></li>
                            <li><a onclick="btn_export('XML')">XML</a></li>
                            <li><a onclick="btn_export('PNG')">PNG</a></li>
                            <li><a onclick="btn_export('CSV')">CSV</a></li>
                            <li><a onclick="btn_export('TXT')">TXT</a></li>
                            <li><a onclick="btn_export('SQL')">SQL</a></li>
                            <li><a onclick="btn_export('Word')">MS-Word</a></li>
                            <li><a onclick="btn_export('Excel')">Ms-Excel</a></li>
                            <li><a onclick="btn_export('Powerpoint')">Ms-Powerpoint</a></li>
                            <li><a onclick="btn_export('PDF')">PDF</a></li>
                        </ul>
                    </div>
                </div>
                <div class="search">
                    <table>
                        <tr>
                            <td>
                                <div class="input-group">
                                    <input id="txt_keyword" type="text" class="form-control" placeholder="关键字" style="width: 200px;" />
                                    <span class="input-group-btn">
                                        <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                                    </span>
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridList"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</body>
</html>